package com.example.hackernerd;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class CustomOnItemSelectedListener implements OnItemSelectedListener {

	private int getType(AdapterView<?> parent) {
		switch (parent.getSelectedItemPosition()) {
		case 0:
			return R.array.dictionaries; 
		case 1:	
			return R.array.concepts;
		default:	
			return R.array.dictionaries;
		}
	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
				// Create an ArrayAdapter using the string array and a default spinner layout
		ArrayAdapter<CharSequence> adapter = 
			ArrayAdapter.createFromResource(
				parent.getContext(),
				getType(parent), 
				android.R.layout.simple_spinner_item);
		// Specify the layout to use when the list of choices appears
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// Apply the adapter to the spinner
		Spinner spinner = (Spinner)((MainActivity)parent.getContext()).findViewById(R.id.type_spinner);
		spinner.setAdapter(adapter);
		Toast.makeText(parent.getContext(), 
				"OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
				Toast.LENGTH_SHORT).show();		
	}
	
	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub

	}

}
